package com.yanqu.road.server.cmd.cross.player;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_CROSS_TO_QUERY_PLAYER_RESP, desc = "跨服查看玩家响应")
public class CrossQueryPlayerRespCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		DecorationProto.CrossQueryPlayerRespMsg reqMsg = DecorationProto.CrossQueryPlayerRespMsg.parseFrom(packet.getBytes());
		DecorationProto.QueryPlayerRespMsg.Builder respMsg = DecorationProto.QueryPlayerRespMsg.newBuilder();
		respMsg.setRet(ret);
		if (0 == ret) {
			respMsg.setUserData(reqMsg.getUserData());
			respMsg.addAllDecorationList(reqMsg.getDecorationListList());
			respMsg.addAllBadge(reqMsg.getBadgeList());
			String ipAddress = reqMsg.getIpAddress();
			if (!StringUtils.isNullOrEmpty(ipAddress)) {
				respMsg.setIpAddress(ipAddress);
			}
		}
		player.sendPacket(Protocol.U_QUERY_PLAYER, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
